﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;

namespace Yuanlin.Business
{
    public class AquacultureFeedbackEditControl : YuanlinUserControl,
        IReplyConverter<AquacultureFeedbackReply, GetOperation>
    {
        protected ValuedTextBox greenNumberValuedTextBox;
        protected ValuedTextBox titleValuedTextBox;
        protected ValuedTextBox phoneValuedTextBox;
        protected ValuedTextBox emailValuedTextBox;
        protected ValuedTextBox qqValuedTextBox;
        protected IButton BackButton;
        private AquacultureFeedback aquacultureFeedback;
        private int categoryType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryType);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetAquacultureFeedbackRequest(this));
        }

        protected override void OnLoad(EventArgs e)
        {
            BackButton.Click += new EventHandler(BackButton_Click);
        }

        private void Bind()
        {
            if (aquacultureFeedback != null)
            {
                this.greenNumberValuedTextBox.Value = aquacultureFeedback.GreenNum.Value;
                this.titleValuedTextBox.Value = aquacultureFeedback.Title.Value;
                this.phoneValuedTextBox.Value = aquacultureFeedback.CompanyContactPhone.Value;
                this.emailValuedTextBox.Value = aquacultureFeedback.CompanyEmail.Value;
                this.qqValuedTextBox.Value = aquacultureFeedback.CompanyQQ.Value;
            }   
        }

        public void BackButton_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect(SiteUrls.Instance().GetAquacultureFeedbackListUrl(categoryType));
        }

        #region IReplyConverter<AquacultureFeedbackReply,GetOperation> Members

        public void ConvertReply(AquacultureFeedbackReply reply, GetOperation operation)
        {
            if (reply != null)
            {
                aquacultureFeedback = reply.Entity as AquacultureFeedback;

                if (!Page.IsPostBack && !AjaxManager.IsCallBack)
                {
                    Bind();
                }
            }
        }

        #endregion
    }
}